package com.studyadmin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.studyadmin.entity.StudentVideo;
import com.studyadmin.mapper.StudentVideoMapper;
import com.studyadmin.service.StudentVideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.studyadmin.util.JsonUtil;
import lombok.val;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lyl
 * @since 2023-03-25
 */
@Service
public class StudentVideoServiceImpl extends ServiceImpl<StudentVideoMapper, StudentVideo> implements StudentVideoService {
    @Autowired(required = false)
    StudentVideoMapper studentVideoMapper;


    /**
     *  根据章节id 查找历史视频记录
     * @param chaId 章节id
     * @param  stuNum
     * @return 查询lastTime
     */
    @Override
    public JsonUtil videoProgress(String chaId,String stuNum) {
        JsonUtil jsonUtil = new JsonUtil();
        QueryWrapper<StudentVideo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("cha_id",chaId).eq("stu_num",stuNum);

        StudentVideo studentVideo=studentVideoMapper.selectOne(queryWrapper.select("last_time","accomplish_flag"));
        System.out.println("数据："+studentVideo);
        if (studentVideo==null){
            jsonUtil.setCode(1);
            jsonUtil.setMsg("未知错误");
        }else {
            jsonUtil.setCode(0);
            jsonUtil.setData(studentVideo);
            jsonUtil.setMsg("查询成功");
        }
        return jsonUtil;
    }
}
